#!/usr/bin/env python3
"""简化版服务器启动脚本"""

import sys
import os

# 设置Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

# 设置编码
os.environ['PYTHONIOENCODING'] = 'utf-8'

try:
    # 导入并启动应用
    from medical_report_api.main import app
    import uvicorn

    print("="*50)
    print("病历掌上查接口服务")
    print("="*50)
    print(f"应用: {app.title}")
    print(f"版本: {app.version}")
    print("="*50)
    print("服务地址: http://localhost:8000")
    print("API文档: http://localhost:8000/docs")
    print("备用文档: http://localhost:8000/redoc")
    print("健康检查: http://localhost:8000/health")
    print("="*50)
    print("按 Ctrl+C 停止服务")
    print("="*50)

    # 启动服务
    uvicorn.run(
        "medical_report_api.main:app",
        host="127.0.0.1",
        port=8000,
        reload=False,  # 禁用重载避免编码问题
        log_level="info"
    )

except KeyboardInterrupt:
    print("\n服务已停止")
except Exception as e:
    print(f"\n启动失败: {e}")
    import traceback
    traceback.print_exc()
    sys.exit(1)